#!/bin/bash -e

hostsloc=/root/nagios/hosts-lists
location=/root/nagios/nrpe-distribution-jams

host=$1
echo "***"
echo "Determining arch of host $host"
arch=`ssh -o ConnectTimeout=100 $host '/bin/uname -m;'`
lib=`$location/nrpe-jams-libname.py $arch`
echo "Working with arch $arch"
scp -o ConnectTimeout=100 $location/nrpe-files/check_* $host:/usr/$lib/nagios/plugins/.
scp -o ConnectTimeout=100 $location/nrpe-files/nrpe-host-$arch.cfg $host:/etc/nagios/nrpe.cfg 
# TODO -- figure out how to do the nrpe restart seamlessly
ssh -o ConnectTimeout=100 $host -x "chmod o+x /usr/$lib/nagios/plugins/check_* ; /etc/init.d/nagios-nrpe-server restart ; /etc/init.d/nrpe restart"

